<%@ page language="java" contentType="text/html; charset=utf-8"%>
<%@ page import="weaver.hrm.HrmUserVarify"%>
<%@ page import="weaver.hrm.User"%>
<%@ page import="weaver.conn.RecordSet" %>
<%@ page import="weaver.general.*" %>
<%@ page import="weaver.general.Util" %>
<jsp:useBean id="RecordSet" class="weaver.conn.RecordSet" scope="page" />
<jsp:useBean id="rs" class="weaver.conn.RecordSet" scope="page" />
<%@ page import="java.net.URLDecoder"%>
<%
/**

		工单报表---新媒体
		工单报表---新媒体

*/
BaseBean baseBean = new BaseBean();
RecordSet res = new RecordSet();
//获取当前登录用户
User user = HrmUserVarify.getUser (request , response) ;
//如果用户为空直接返回
if(user == null)  return ;
//获取当前用户部门id
int departmentid = user.getUserDepartment();
//获取当前用户UID
int userId =  user.getUID();
//输出日志
baseBean.writeLog("================"+userId);
baseBean.writeLog("================"+departmentid);
//查询当前登录人所拥有的权限
//根据角色查询   总经理角色id=46   财务经理角色id=53
String sfrUrl = "http://221.239.33.59:8075/WebReport/ReportServer?reportlet=";
String sfrSrc = "";//iframe超链接地址
String sfrTitle = "";//报表名称
String isiframe = "";//是否本页面iframe打开

//帆软报表的路径以及显示所有字段参数   默认把userid传递过去
sfrSrc = "gongdan_xinmeiti.cpt&__bypagesize__=false&userId="+userId;

//直接拼接地址
sfrUrl += sfrSrc;

String sql = "";


String root = "&root=0";//默认为0，如果没有传递root值就全部数据不可查

 //管理员直接跳转
if(userId == 1){
	sfrUrl = sfrUrl+sfrSrc+"&__bypagesize__=false&userId="+userId+root;
	response.sendRedirect(sfrUrl);
		return;
}


//浩智-新媒体特权角色看全部
sql = "select * from hrmroles hr,hrmrolemembers hrmr,hrmresource hrm where hr.id = hrmr.roleid and hrm.id = hrmr.resourceid and rolesmark like '%晧智-新媒体报表特权%' and hrm.id = '"+userId+"'";
res.execute(sql);
if(res.next()){
	//当前用户是总经理或者是财务经理
	root = "&root=1";
	sfrUrl = sfrUrl+root;
	if(!"0".equals(isiframe)){
		response.sendRedirect(sfrUrl); 
		return;
	}
} 
//======新媒体工单目前一种情况======

//情况1:总经理财务经理、侯金凯、可以查看所有报表
//查询当前登录用户是否是总经理
sql = "select * from hrmrolemembers where resourceid='"+userId+"' and (roleid='46' or roleid='53' or roleid = '32'  )";
res.execute(sql);
if(res.next() || userId ==28){
	//当前用户是总经理或者是财务经理
	root = "&root=1";
	sfrUrl = sfrUrl+root;
	if(!"0".equals(isiframe)){
		response.sendRedirect(sfrUrl); 
		return;
	}
} 

//新媒体员工可以看自己的报表
sql = "select * from hrmresource where departmentid = 9 and id = '"+userId+"'";
res.execute(sql);
if(res.next() ){
	//当前用户是总经理或者是财务经理
	root = "&root=2";
	sfrUrl = sfrUrl+root;
	if(!"0".equals(isiframe)){
		response.sendRedirect(sfrUrl); 
		return;
	}
} 


String other = "error.jsp";
response.sendRedirect(other);

%>
<!DOCTYPE html>   
<html>       
<head>       
<title><%=sfrTitle%></title>       
<script type="text/javascript"> 
var sfrSrc = "<%=sfrSrc%>";
if(sfrSrc==""){
	alert("无法正确解析找到相应的帆软报表文件,请不要修改地址栏的参数")
	window.close();
}
//cjkEncode方法的实现代码，放在网页head中或者用户自己的js文件中  
var sfrUrl = "<%=sfrUrl%>";
function cjkEncode(text) {                                                                             
  if (text == null) {          
    return "";          
  }          
  var newText = "";          
  for (var i = 0; i < text.length; i++) {          
    var code = text.charCodeAt (i);           
    if (code >= 128 || code == 91 || code == 93) {  //91 is "[", 93 is "]".          
      newText += "[" + code.toString(16) + "]";          
    } else {          
      newText += text.charAt(i);          
    }          
  }          
  return newText;          
}      
function autoLoad() {  
  var addr = cjkEncode(sfrUrl);   
  //var addr = sfrUrl;   
  document.getElementById("reportFrame").src = addr;   
}   
window.onload = autoLoad; 
</script>       
</head>       
<body style="margin:0px;">        
<iframe id="reportFrame"  src="" style="width:100%;height:800px;" ></iframe>       
</body>       
</html> 